import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },
  // {
  //   path: '/profile',
  //   component: Layout,
  //   redirect: '/profile',
  //   hidden: true,
  //   children: [
  //     {
  //       path: '',
  //       component: () => import('@/views/profile/index'),
  //       name: 'Profile',
  //       meta: { title: 'Profile', icon: 'user', noCache: true }
  //     }
  //   ]
  // },
  {
    path: '/',
    component: Layout,
    children: [{
      path: '',
      name: 'DashHome',
      component: () => import('@/views/home/index'),
      meta: { title: '工作台', icon: 'home' }
    }]
  }

  // {
  //   path: '/rds',
  //   component: Layout,
  //   name: 'rds',
  //   meta: {
  //     title: '数据库',
  //     icon: 'el-icon-s-data'
  //   },
  //   children: [
  //     {
  //       path: 'cluster',
  //       name: 'Cluster',
  //       component: () => import('@/views/rds/cluster/index'),
  //       meta: { title: '集群管理', icon: 'home' }
  //     },
  //     {
  //       path: 'cluster/:clusterId',
  //       name: 'ClusterDetail',
  //       component: () => import('@/views/rds/cluster/components/ClusterDetail'),
  //       meta: { title: '集群详情', icon: 'home' },
  //       hidden: true
  //     },
  //     {
  //       path: 'instance',
  //       name: 'Instance',
  //       component: () => import('@/views/rds/instance/index'),
  //       meta: { title: 'Instance管理', icon: 'home' }
  //     },
  //     {
  //       path: 'instance/:instanceId',
  //       name: 'InstanceDetail',
  //       component: () => import('@/views/rds/instance/components/InstanceDetail'),
  //       meta: { title: 'Instance详情', icon: 'home' },
  //       hidden: true

  //     },
  //     {
  //       path: 'job',
  //       name: 'Job',
  //       component: () => import('@/views/transfer/job/index'),
  //       meta: { title: '数据传输', icon: 'home' }
  //     },
  //     {
  //       path: 'job/:jobId',
  //       name: 'JobDetail',
  //       component: () => import('@/views/transfer/job/components/JobDetail'),
  //       meta: { title: 'Job详情', icon: 'home' },
  //       hidden: true
  //     }
  //   ]
  // },
  // {
  //   path: '/cmdb',
  //   component: Layout,
  //   name: 'cmdb',
  //   meta: {
  //     title: '中间件管理',
  //     icon: 'el-icon-s-data'
  //   },
  //   children: [
  //     {
  //       path: 'asset',
  //       name: 'Asset',
  //       component: () => import('@/views/cmdb/asset/index'),
  //       meta: { title: '资产管理', icon: 'home' }
  //     },
  //     {
  //       path: 'asset/:assetId',
  //       name: 'AssetDetail',
  //       component: () => import('@/views/cmdb/asset/components/AssetDetail'),
  //       meta: { title: '资产详情', icon: 'home' },
  //       hidden: true

  //     }
  //   ]
  // },
  // {
  //   path: '/middle',
  //   component: Layout,
  //   name: 'cmdb',
  //   meta: {
  //     title: '中间件管理',
  //     icon: 'el-icon-s-data'
  //   }, children: [
  //     // {
  //     //   path: 'service',
  //     //   name: 'Service',
  //     //   component: () => import('@/views/cmdb/service/index'),
  //     //   meta: { title: 'Service管理', icon: 'home' }
  //     // },
  //     {
  //       path: 'redis',
  //       name: 'ServiceRedis',
  //       component: () => import('@/views/cmdb/service/index'),
  //       meta: { title: 'Redis管理', icon: 'home' }
  //     },
  //     {
  //       path: 'dfs',
  //       name: 'ServiceDfs',
  //       component: () => import('@/views/cmdb/service/index'),
  //       meta: { title: 'Dfs管理', icon: 'home' }
  //     },
  //     {
  //       path: 'es',
  //       name: 'ServiceEs',
  //       component: () => import('@/views/cmdb/service/index'),
  //       meta: { title: 'ES管理', icon: 'home' }
  //     },
  //     {
  //       path: 'service/:serviceId',
  //       name: 'ServiceDetail',
  //       component: () => import('@/views/cmdb/detail/index'),
  //       meta: { title: 'Service详情', icon: 'home' },
  //       hidden: true

  //     }
  //   ]
  // },
  // {
  //   path: '/app',
  //   component: Layout,
  //   name: 'app',
  //   meta: {
  //     title: '应用管理',
  //     icon: 'el-icon-s-data'
  //   },
  //   children: [
  //     {
  //       path: 'appname',
  //       name: 'AppName',
  //       component: () => import('@/views/appid/appname/index'),
  //       meta: { title: 'AppName', icon: 'home' }
  //     },
  //     {
  //       path: 'appname/:appnameId',
  //       name: 'AppNameDetail',
  //       component: () => import('@/views/appid/appname/components/AppnameDetail'),
  //       meta: { title: 'AppName详情', icon: 'home' },
  //       hidden: true

  //     }
  //   ]
  // }
]

/**
 * asyncRoutes
 * the routes that need to be dynamically loaded based on user roles
 */
export const asyncRoutes = [

  {
    path: '/ticket',
    component: Layout,
    name: '数据变更',
    meta: {
      title: '数据变更',
      icon: 'sql',
      affix: true
    },
    children: [
      {
        path: 'order',
        name: 'Order',
        // alwaysShow: false,
        component: () => import('@/views/ticket/order/index'),
        meta: { title: '我的工单', icon: 'el-icon-user-solid' }
      },
      {
        path: 'audit',
        name: 'Audit',
        // alwaysShow: false,
        component: () => import('@/views/ticket/order/Audit'),
        meta: { title: '工单审批', icon: 'el-icon-user-solid', roles: ['admin'] }
      },
      {
        path: 'audit/:orderId',
        name: 'AuditDetail',
        component: () => import('@/views/ticket/order/components/OrderDetail'),
        meta: { title: '工单审批', icon: 'el-icon-user-solid', roles: ['admin'] },
        hidden: true
      },
      {
        path: 'apply/ddl',
        name: 'ApplyDdl',
        component: () => import('@/views/ticket/order/components/ApplyDdl'),
        meta: { title: 'DDL工单申请', icon: 'el-icon-user-solid' }
      },
      {
        path: 'apply/dml',
        name: 'ApplyDml',
        component: () => import('@/views/ticket/order/components/ApplyDml'),
        meta: { title: 'DML工单申请', icon: 'el-icon-user-solid' }
      },
      // {
      //   path: 'apply/query',
      //   name: 'ApplyQuery',
      //   component: () => import('@/views/ticket/order/components/ApplyQuery'),
      //   meta: { title: 'Query工单申请', icon: 'el-icon-user-solid' }
      // },
      {
        path: 'order/:orderId',
        name: 'OrderDetail',
        component: () => import('@/views/ticket/order/components/OrderDetail'),
        meta: { title: '工单详情', icon: 'el-icon-user-solid' },
        hidden: true
      }

      // {
      //   path: 'order/:orderId',
      //   name: 'OrderDetail',
      //   component: () => import('@/views/ticket/order/components/OrderDetail'),
      //   meta: { title: '工单详情', icon: 'home' },
      //   hidden: true
      // },
      // {
      //   path: 'order/apply',
      //   name: 'OrderApply',
      //   component: () => import('@/views/ticket/order/components/OrderApply'),
      //   meta: { title: '申请工单', icon: 'sql' },
      //   hidden: true
      // }
    ]
  },
  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
